package lib.bone.oss.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lib.bone.common.core.domain.ResponseDTO;
import lib.bone.oss.constant.FileServiceTypeEnum;
import lib.bone.oss.domain.entity.FileEntity;
import lib.bone.oss.service.impl.FileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

/**
 * @author  kindear
 */
@Slf4j
@RestController
@Api(tags = "文件管理")
public class FileController {
    @Autowired
    FileService fileService;


    @ApiOperation(value = "文件上传(local)", notes = "文件本地上传")
    @PostMapping("/file/local/upload")
    public ResponseDTO<FileEntity> localUpload(MultipartFile file, @RequestParam(value = "fileName",required = false) String fileName) throws Exception {
        log.info(fileName);
        return fileService.fileUpload(file, FileServiceTypeEnum.LOCAL,"base",fileName);
    }




    @RequestMapping("file/{fileId}")
    @ApiOperation(value = "文件下载(stream)")
    public ResponseEntity<byte[]> downLoadById(@PathVariable("fileId") String fileId, HttpServletRequest request) {
        return fileService.downLoadById(fileId, request);
    }

    /**
     * 文件预览
     */
    @ApiIgnore
    @RequestMapping("file/viewer/{fileId}")
    @ApiOperation(value = "文件预览(stream)")
    public void viewFile(@PathVariable("fileId") String fileId,HttpServletRequest request){

    }

}
